<template>
   <div class="bgt" :style="backgroundStyle">
    <div class="content">
      <van-tabs v-model="activeName" color="#1677FF" @change="changeHd">
        <van-tab title="红榜" name="1"></van-tab>
        <van-tab title="黑榜" name="2"></van-tab>
      </van-tabs>
      <div class="hhb-table">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
          <van-cell v-for="(item,index) in dealHbh" :key="index">
            <div>
              <div class="title">{{ item.remark }}</div>
              <div class="time">{{ item.createdTime }}</div>
            </div>
          </van-cell>
        </van-list>
      </div>
    </div>
  </div>
</template>

<script>
import { hbbList } from '@/api/info';
let drp = window.localStorage.getItem('dpr');
export default {
  name: 'bgt',
  data() {
    return {
      bgImg: 'url(' + require("@/images/hbg_@" + drp + "x.png") + ')',
      list: [
        { remark: '普陀山朱家尖"普陀山·居"红榜(第四期)', createdTime: '2024-08-26', type: '1' },
        { remark: '普陀山朱家尖"普陀山·居"红榜(第三期)', createdTime: '2024-07-12', type: '1' },
        { remark: '普陀山朱家尖"普陀山·居"红榜(第二期)', createdTime: '2024-06-07', type: '1' },
        { remark: '普陀山朱家尖"普陀山·居"红榜(第一期)', createdTime: '2024-05-09', type: '1' },
        // { remark: '普陀山朱家尖餐饮食品红榜(第二十四期)', createdTime: '2024-09-20', type: '1' },
        // { remark: '普陀山朱家尖餐饮食品黑榜(第二十一期)', createdTime: '2024-08-05', type: '2' },
        { remark: '普陀山朱家尖"普陀山·居"黑榜(第二期)', createdTime: '2024-07-12', type: '2' },
        { remark: '普陀山朱家尖"普陀山·居"黑榜(第一期)', createdTime: '2024-06-07', type: '2' },
      ],
      loading: false,
      error: true,
      finished: true,
      activeName: '1',
      params: {
        pageNum: 1,
        pageSize: 10,
        type: ''
      },
      total: 0
    }
  },
  mounted() {
    // this.hbbList();
  },
  computed: {
    backgroundStyle() {
      return {
        backgroundImage: this.bgImg
      }
    },
    dealHbh() {
      let { activeName, list } = this;
      return list.filter(item => {
        if(item.type == activeName) {
          return item;
        }
      })
    }
  },
  methods: {
    onLoad() {
      this.loading = true;
      if(this.total > this.params.pageNum * this.params.pageSize) {
        this.params.pageNum++;
        // this.hbbList();
      } else {
        this.finished = true;
      }
    },
    hbbList() {
      let params = this.params;
      params.type = this.activeName;
      hbbList(this.params).then(res => {
        // console.log(res)
        if(res.code == 200) {
          this.loading = false
          this.list = res.rows;
          this.total = res.total;
        }
      })
    },
    changeHd() {
      this.params.pageNum = 1;
      this.total = null;
      // this.hbbList();
    }
  }
}
</script>

<style lang="less" scoped>
.bgt {
  background-size: 100% 190px;
  background-repeat: no-repeat;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  background-position: top center;
  background-color: #F8F8F8;
  .content {
    padding: 14px 16px;
    box-sizing: border-box;
    .hhb-table {
      .title {
        color: #333333;
        font-family: PingFang SC;
        font-weight: regular;
        font-size: 16px;
        line-height: 24px;
        letter-spacing: 0px;
        text-align: left;
      }
      .time {
        color: #999999;
        font-family: PingFang SC;
        font-weight: regular;
        font-size: 14px;
        line-height: 22px;
        letter-spacing: 0px;
        text-align: left;
      }
      /deep/ .van-tabs__nav {
        border-radius: 10px;
      }
    }
  }
}
</style>